﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Incominginformations;

namespace MyMES.Writer.API.Application.CommendHandlers.Incominginformations
{
    public class UpdataStorageStaturCommendHandlers : IRequestHandler<UpdataStorageStaturCommends, APIResult<Arrivalnotice>>
    {
        private readonly IBaseRepository<Arrivalnotice> arrivalnoticeRepository;
        private readonly IMapper mapper;

        public UpdataStorageStaturCommendHandlers(IBaseRepository<Arrivalnotice> arrivalnoticeRepository, IMapper mapper)
        {
            this.arrivalnoticeRepository = arrivalnoticeRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 更新入库状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Arrivalnotice>> Handle(UpdataStorageStaturCommends request, CancellationToken cancellationToken)
        {
            var result = new APIResult<Arrivalnotice>();



            string sql = $"UPDATE Incominginformation  SET NoticePurchase = 4  WHERE StorageId = @StorageId   ";
            // 4. 明确传递参数
            var enter = mapper.Map<Incominginformation>(request);

            // 调用仓储层
            await arrivalnoticeRepository.Updatestatus(enter, sql);
            result.Code = APIEnum.修改成功;
            result.Msg = "状态更新成功";
            return result;

        }
    }
}
